/**
 * Created by 55456 on 2016/4/8.
 */
var sequelizex = require("../lib/sequelizex");
var shortTypes = sequelizex.DataTypes;
module.exports = (sequelize,DataTypes) => {
    sequelize.define("Comment",{
        content:shortTypes.Text(),
        updatedAt : {
            type : DataTypes.STRING
        },

        createdAt : {
            type : DataTypes.STRING
        }
    },{
        timestamps : false,
        hooks:{
            beforeCreate:function(comment){
                comment.createdAt = Math.round(new Date().getTime()/1000);
                comment.updatedAt = Math.round(new Date().getTime()/1000);
            },
            beforeUpdate:function(comment){
                comment.updatedAt = Math.round(new Date().getTime()/1000);
            }
        },
        associate : function(models){
            models.Comment.hasMany(models.Comment,{ as : "RevComment",foreignKey:"RevCommentId"});
            models.Comment.belongsTo(models.User,{through:"UserId"});
            models.Comment.belongsTo(models.Story,{through:"StoryId"});
        }
    });
};